define([
        'app/utils/WebUtils',
        'app/service/GeneralServices',
        'underscore',
        'app/utils/AMUICookieUtils',
        'app/utils/CommonUtils'
        
        
        ], function (
        WebUtils,
        gs,
        _,
        AMUICookieUtils
    ) {
	var opt ={};
	var p1 = {};
	
	opt = p1 = AMUICookieUtils.initializePage();
	
	gs.wjt_create_init(p1, function(resp){
		if(resp.status == "500"){
			WebUtils.alert("连接错误，请刷新页面重试！");	
			return;
		}
		
		opt.navi_main = "新建微讲堂";
		opt.navi_sub = "创建你的知识微讲堂";
		
		var catalogs = resp.result.catalogs;
		
		WebUtils.adminPageInt(opt);
		
		$("#wjt_room_starttime").val($.timeFormat2((new Date()).getTime()));
		
		//select
		if(typeof(catalogs.length) !="undefined"){
			
			if(catalogs.length > 2){

				$("#wjt_room_catalog").html("");
				$("#wjt_room_catalog").append("<option value=\"\">不选择</option>");
				
				for(var i = 2; i < catalogs.length; i++){
					var option_item = "<option value=\""+catalogs[i].uuid+"\">"+catalogs[i].name+"</option>";
					$("#wjt_room_catalog").append(option_item);	
				}
				
				$(".wjt_room_catalog_container").show();
			}else{
				$(".wjt_room_catalog_container").hide();
			}
		}
		
		
	});
	
	$("#wjt_room_create_btn").click(function(){
		
		var name = $.val_trim($("#wjt_room_name").val());
		var starttime = $.val_trim($("#wjt_room_starttime").val());
		
		if($.isNullStr(name)){
			WebUtils.alert("微讲堂名称不能为空");
			return;
		}
		if(name.length >50){
			WebUtils.alert("微讲堂名称不能超过50字");
			return;
		}
		if($.isNullStr(starttime)){
			WebUtils.alert("请设置开始时间");
			return;
		}
		var createpwd = $('[name="wjt-createpwd-options"]').filter(':checked').val();
		
		var cataloguuid = $.val_trim($("#wjt_room_catalog").val());

		var $btn = $(this);
		$btn.button('loading');
		var p ={
			"useruuid":opt.useruuid,
			"name":name,
			"starttime":starttime,
			"createpwd":createpwd,
			"cataloguuid":cataloguuid
		};
		
		gs.wjt_roomcreate(p,function(resp){
			
			$btn.button('reset');
			
			if(resp.status == "500"){
				if($.isNullStr(resp.result)){
					WebUtils.alert("操作不成功，请重试！");					
				}else{
					WebUtils.alert(resp.result);
				}
			}else{
//				WebUtils.alert("创建成功，请继续完善信息");
				$.redirectTo("admin-roomdetails.html?roomuuid="+resp.result.roomuuid);
			}
			
		});

	});
	
	return;
});